/*
 * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xdlink.component.resolver.impl;

import android.support.annotation.NonNull;

import com.xuexiang.xdlink.component.message.IResponseMessage;
import com.xuexiang.xdlink.component.resolver.IResolveResult;

import java.util.ArrayList;
import java.util.List;

/**
 * 简单的解析结果
 *
 * @author xuexiang
 * @since 2018/8/26 下午7:05
 */
public class SimpleResolveResult implements IResolveResult {

    /**
     * 解析出来的消息集合
     */
    private List<IResponseMessage> Messages;

    /**
     * 已解析的数据长度
     */
    private int ResolvedLength;

    @Override
    public int getResolvedLength() {
        return ResolvedLength;
    }

    @Override
    public List<IResponseMessage> getMessages() {
        return Messages;
    }

    public SimpleResolveResult setMessages(@NonNull List<IResponseMessage> messages) {
        Messages = messages;
        return this;
    }

    public SimpleResolveResult putMessage(IResponseMessage message) {
        if (message != null) {
            if (Messages == null) {
                Messages = new ArrayList<>();
            }
            Messages.add(message);
        }
        return this;
    }

    public SimpleResolveResult setResolvedLength(int resolvedLength) {
        ResolvedLength = resolvedLength;
        return this;
    }
}
